//ai被击倒逻辑
params ["_unit", "_player"];

//延时5s准备
Sleep 5;
if(!alive _unit)exitWith{};

//有概率使用自爆10米外 150米内
private _dis = _unit distance2d _player;
if(_dis > 10 && {_dis < 150})then{
	if(random 100 < as_ai_down)then{
		private _ogn = "APERSMine_Range_Ammo" createVehicle position _unit;//由于手雷无法创建，只好创建为其他物品
		_ogn attachTo [_unit, [0, 0, 0.075], "righthand"];
		[_unit, _ogn] spawn{
			params ["_unit", "_ogn"];
			private _player = objNull;
			waitUntil{
				Sleep 2;
				_player = [_unit, 2] call fn_getPlayerNear;
				(!alive _unit) || {!isNull _player}
			};
			//死亡和玩家靠近，都会导致手雷释放
			detach _ogn;
			_ogn setDamage 1;
		};
	};
}
else{
	//距离大于200米并且，且附近没有玩家，则呼叫队友救治
	if(_dis > 200
	&& {isNull ([_unit, 50] call fn_getPlayerAttack)})then{	
		if(Param_Debug == 1)then{systemchat "触发ai救队友！"};
		[_unit] spawn fn_aiCallMedic;
	};
};


for ("_i") from 1 to 12 do {
	Sleep 15;
	if(!alive _unit
	|| {lifeState _unit != "INCAPACITATED"})exitWith{};
	[_unit, selectRandom asa_pain] remoteExec ["playMove", 0];
	[_unit, selectRandom ast_bleed] remoteExec ["say3D", 0];
};



//流血过多死亡
if(alive _unit
&& {lifeState _unit == "INCAPACITATED"})then{
	if(isPlayer _player
		&& _player call fn_isPlayerRed)then{
			//触发击杀效果（提示和加钱）
			[_unit, _player] remoteExec ["fn_killEffect", _player];
		};
	_unit setDamage 1;
};